package cn.funeralobjects.upms.api;

import cn.funeralobjects.common.web.api.RestEnableApi;
import cn.funeralobjects.common.web.api.RestEntityApi;
import cn.funeralobjects.upm.web.model.VApi;
import cn.funeralobjects.upms.enums.HttpMethod;
import cn.funeralobjects.upms.model.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * Api的Api
 *
 * @author FuneralObjects
 * Create date: 2020/4/30 5:01 PM
 */
@Validated
public interface ApiApi extends RestEntityApi<VApi, Integer>, RestEnableApi<VApi, Integer> {

    /**
     * 添加 HTTP 的Api
     *
     * @param scope  api所属范围
     * @param method HTTP方法
     * @param url    地址
     * @param name   名称
     * @return 添加完成的API
     */
    @PostMapping("/{scope}/http")
    Mono<VApi> addHttpApi(@PathVariable String scope,
                          @RequestParam HttpMethod method,
                          @RequestParam @NotBlank String url,
                          @RequestParam(required = false) String name);

    /**
     * 批量添加更新api集合
     *
     * @param apis api集合
     * @return 添加/更新完的API集合
     */
    @PostMapping("/batch")
    Mono<List<VApi>> addOrUpdateInBatch(@RequestBody @NotEmpty List<Api> apis);

    /**
     * 添加 WS 的API
     *
     * @param scope api所属范围
     * @param url   地址
     * @param name  名称
     * @return 添加完成的API对象
     */
    @PostMapping("/{scope}/ws")
    Mono<VApi> addWsApi(@PathVariable String scope,
                        @RequestParam @NotBlank String url,
                        @RequestParam(required = false) String name);


    @GetMapping("/all")
    Mono<List<VApi>> findAll();
}
